package com.lingx.model.impl.interpreter;

import org.springframework.stereotype.Component;

import com.lingx.model.impl.AbstractInterpreter;
@Component
public class ByteInterpreter  extends AbstractInterpreter{
	private static final long serialVersionUID = 6428029760172871233L;

	public ByteInterpreter() {
		super("ByteInterpreter","字节显示格式转换MB");
	}
	@Override
	public Object input(Object value) throws Exception {
		return null;
	}

	@Override
	public Object output(Object value) throws Exception {
		double num=Double.parseDouble(value.toString());
		
		if(num/1024>1) {
			num=num/1024;
			if(num/1024>1) {
				num=num/1024;
				if(num/1024>1) {
					num=num/1024;
					value=String.format("%.2fGB", num);
				}else {
					value=String.format("%.2fMB", num);
				}
			}else {
				value=String.format("%.2fKB", num);
			}
		}else {
			value=num+"B";
		}
		return value;
	}

	public static void main(String args[]) {
		ByteInterpreter obj=new ByteInterpreter();
		
		try {
			System.out.println(obj.output(87020123000l));
			System.out.println(obj.output(87020123));
			System.out.println(obj.output(87020));
			System.out.println(obj.output(87));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
